﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InControl
{
    public partial class INV_Edit_form : Form
    {
        private String id;

        public INV_Edit_form()
        {
            InitializeComponent();
        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {
            ((INV_MDIParent)this.MdiParent).OpenForm(typeof(INV_office_form));
        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {

        }

        private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
        {
            //((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox1, "item_table", "name", "id");

        }

        private void INV_Edit_form_Load(object sender, EventArgs e)
        {
            ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox4, "item_table", "name", "id", 0);
            ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox1, "cat_table", "category", "id", 0);
            ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox2, "type_table", "type_", "id", 0);
            ((INV_MDIParent)this.MdiParent).appDriver.FillCombo(comboBox3, "inven_table", "location", "id", 0);
            Nullify();
            //comboBox4.Text = "Please Select...";
            //Welcome_1_Label.Text = ((INV_MDIParent)this.MdiParent).appDriver.getfullName() + ",";
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Off_Edit_Panel_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            try
            {
                if (comboBox4.SelectedValue.ToString() == "0" || comboBox1.SelectedValue.ToString() == "0" ||
                    comboBox2.SelectedValue.ToString() == "0" || comboBox3.SelectedValue.ToString() == "0" ||
                    textBox6.Text == "" || textBox4.Text == "" )
                    throw new Exception("please complete form");
                ((INV_MDIParent)this.MdiParent).appDriver.UpdateItem(id, comboBox4.Text, textBox4.Text, comboBox1.SelectedValue.ToString(), comboBox2.SelectedValue.ToString(), comboBox3.SelectedValue.ToString(), textBox6.Text);
                Error_form ef = new Error_form();
                ef.richTextBox1.Text = "successful update";
                ef.ShowDialog(this);
                textBox9.Text = ((INV_MDIParent)this.MdiParent).appDriver.GetQuantity(comboBox4.SelectedValue.ToString()).ToString();
            }
            catch (Exception ex)
            {
                Error_form ef = new Error_form();
                ef.richTextBox1.Text = ex.Message;
                ef.ShowDialog(this);
            }
        }

 
        private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
        {
            comboBox1.ForeColor = Color.Red;
        }

        private void comboBox2_SelectionChangeCommitted(object sender, EventArgs e)
        {
            comboBox2.ForeColor = Color.Red;
        }
        
        private void comboBox3_SelectionChangeCommitted(object sender, EventArgs e)
        {
            comboBox3.ForeColor = Color.Red;
        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            textBox6.ForeColor = Color.Red;
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            textBox4.ForeColor = Color.Red;
        }

        private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

          private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void comboBox2_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }

        private void comboBox4_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (comboBox4.SelectedValue.ToString() != "0")
            {
                List<ComboBox> ls = new List<ComboBox>();
                List<TextBox> tl = new List<TextBox>();
                List<Label> tt = new List<Label>();

                tl.Add(textBox4); tl.Add(textBox6);
                ls.Add(comboBox1); ls.Add(comboBox2); ls.Add(comboBox3);

                ((INV_MDIParent)this.MdiParent).appDriver.ComboList(tt, ls, tl, comboBox4.SelectedValue.ToString(), 3);
                textBox9.Text = textBox6.Text;
                id = comboBox4.SelectedValue.ToString();
            }
            else
            {
                Nullify();
            }
        }

        private void Nullify()
        {
            textBox9.Clear(); textBox4.Clear(); textBox6.Clear();
            comboBox1.SelectedValue = 0; comboBox2.SelectedValue = 0; comboBox3.SelectedValue = 0;
        }

    }
}
